/* 计算器（一户有一台就够） */
var Calculator = /** @class */ (function () {
    function Calculator() {
    }
    Calculator.prototype.add = function (a, b) {
        return a + b;
    };
    Calculator.prototype.multiply = function (a, b) {
        return a * b;
    };
    // Calculator.getSingleton()
    Calculator.getSingleton = function () {
        if (!this.singleton) {
            this.singleton = new Calculator();
        }
        return this.singleton;
    };
    /* 确保计算器有且只有一台 singleton=单例/独子 */
    Calculator.singleton = null;
    return Calculator;
}());

/* 很淡腾地创建了无数相同功能的实例 作者死于内存爆炸 */
// const calc1 = new Calculator()
// console.log(calc1.add(2, 3));
// const calc2 = new Calculator()
// console.log(calc2.multiply(2, 3));
// const calc3 = new Calculator()
// console.log(calc3.multiply(5, 6));

/*  */
var calc = Calculator.getSingleton();
console.log(calc.add(2, 3));
var calc2 = Calculator.getSingleton();
console.log(calc2.add(2, 3));
var calc3 = Calculator.getSingleton();
console.log(calc3.add(2, 3));
console.log(calc2 === calc3); //
